獲取裝置資訊的api
從CMMotionManager獲取
1.檢查裝置可不可行
2.
使用pull方式
跟他要
func {accelerometer,gyro,magnetometer,deviceMotion} Update()
2(1)
使用push方式
設定資料回報頻率 ex:30frame
3.建立一個Closure每30frame 會執行一次並且得到資料
var {accelerometer,gyro,magnetometer,deviceMotion} Available :Bool
func {accelerometer,gyro,magnetometer,deviceMotion} Update()
var {accelerometer,gyro,magnetometer,deviceMotion} Active :Bool
func stop {accelerometer,gyro,magnetometer,deviceMotion} Update()
accelerometerData:CMAccelerometerData
會提供一個Struct
struct CMAcceleration{
var x:Double //in g
var y:Double
var z:Double
}
xyz 如果手正持手機那 y=1.0 x,z=0
gyroData:CMGyroData
一樣提供一個Struct
struct CMRotationRate{
var x:Double //radians/s
var y:Double
var z:Double
}
代表旋轉速率
magnetometerData:CMMagnetometerData
一樣提供一個Struct
struct CMMagneticField{
var x:Double //in microteslas
var y:Double
var z:Double
}
告訴你哪個是北邊
透過CMDeviceMotion
var gravity:CMAcceleration
var userAcceleration:CMAcceleration //用戶對手機的加速度
var rotationRate :CMRotationRate
var attitude:CMAttitude // 設備的方位
class CMAttitude :NSObject {
var roll: Double
var pitch : Double
var yaw : Double
}
var magneticField:CMMagnetometerData
struct CMCalibratedMagneticField{
var field : CMMagneticField
var accuracy : CMCalibratedMagneticFieldAccuracy
}
func startAccelerometerUpdates(to queue: OperationQueue,
withHandler handler: @escaping CMAccelerometerHandler)
func startGyroUpdates(to queue: OperationQueue,
withHandler handler: @escaping CMGyroHandler)
func startMagnetometerUpdates(to queue: OperationQueue,
withHandler handler: @escaping CMMagnetometerHandler)
func startDeviceMotionUpdates(using referenceFrame: CMAttitudeReferenceFrame,
to queue: OperationQueue,
withHandler handler: @escaping CMDeviceMotionHandler)
var accelerometerUpdateInterval: TimeInterval { get set }
var gyroUpdateInterval: TimeInterval { get set }
var magnetometerUpdateInterval: TimeInterval { get set }
var deviceMotionUpdateInterval: TimeInterval { get set }